<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/fragment::top">

</head>

<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <div th:replace="common/fragment::leftmenu"></div>
        <!--End 左侧导航-->

        <!--头部信息-->
        <div th:replace="common/fragment::header"></div>
        <!--End 头部信息-->

        <!--页面主要内容-->
        <main class="lyear-layout-content">

            <div class="container-fluid">

                            <div >
                                <form action="#!" class="horizontal " id="add-user-form" method="post">

                                    <!--供应商名-->
                                    <div hidden="hidden" name="supplierid" th:value="${supplier.id}"></div>
                                    <div class="form-group col-md-10 ">
                                        <label class="col-md-2 control-label" for="suppliername" style="text-align: center;line-height: 36px">供应商名</label>
                                        <div class="col-md-8">
                                            <input class="form-control" id="suppliername" name="suppliername"
                                                   placeholder="供应商名" type="text"  th:value="${supplier.name}">
                                            <input hidden="hidden" id="supplierid" th:value="${supplier.id}"></input>
                                        </div>
                                    </div>
                                    <!--供应商地址-->
                                    <div class="form-group col-md-10 ">
                                        <label class="col-md-2 control-label" for="supplieraddress" style="text-align: center;line-height: 36px">供应商地址</label>
                                        <div class="col-md-8">
                                            <input class="form-control" id="supplieraddress" name="supplieraddress"
                                                   placeholder="供应商地址" type="text" th:value="${supplier.address}">
                                        </div>
                                    </div>
                                    <!--联系人-->
                                    <div class="form-group col-md-10 ">
                                        <label class="col-md-2 control-label" for="linkman" style="text-align: center;line-height: 36px">联系人</label>
                                        <div class="col-md-8">
                                            <input class="form-control" id="linkman" name="linkman"
                                                   placeholder="联系人" type="text" th:value="${supplier.linkman}">
                                        </div>
                                    </div>
                                    <!--供应商电话-->
                                    <div class="form-group col-md-10 ">
                                        <label class="col-md-2 control-label" for="phone" style="text-align: center;line-height: 36px">供应商电话</label>
                                        <div class="col-md-8">
                                            <input class="form-control" id="phone" name="phone"
                                                   placeholder="供应商电话" type="text" th:value="${supplier.phone}">
                                        </div>
                                    </div>
                                    <!--供应商email-->
                                    <div class="form-group col-md-10 ">
                                        <label class="col-md-2 control-label" for="email" style="text-align: center;line-height: 36px">供应商email</label>
                                        <div class="col-md-8">
                                            <input class="form-control" id="email" name="email"
                                                   placeholder="供应商email" type="text" th:value="${supplier.email}">
                                        </div>
                                    </div>

                                    <!--供应商状态-->
                                    <div class="input-group col-md-10">
                                        <label class="col-md-2 control-label" style="text-align: center;line-height: 36px">角色状态</label>
                                        <<div class="col-md-8">
                                            <label class="radio-inline" for="supplier-inline-radio1">
                                            <input id="supplier-inline-radio1" name="supplierstatus" type="radio"
                                                   value="1" th:checked="${supplier.getStatus()}==1">
                                            启用
                                            </label>
                                            <label class="radio-inline" for="supplier-inline-radio2">
                                                <input id="supplier-inline-radio2" name="supplierstatus" type="radio"
                                                       value="-1" th:checked="${supplier.getStatus()}==-1">
                                                禁用
                                            </label>
                                        </div>
                                    </div>


                                    <!--供应商注释-->
                                    <div class="form-group col-md-10 ">
                                        <label class="col-md-2 control-label" for="comment" style="text-align: center;line-height: 36px">备注</label>
                                        <div class="col-md-8">
                                            <input class="form-control" id="comment" name="comment"
                                                   placeholder=".....备注....."  type="text" th:value="${supplier.comment}">
                                        </div>
                                    </div>




                                    <div class="form-group col-md-10">
                                        <button
                                                class="btn btn-primary ajax-post col-md-2"
                                                id="add-supplier-btn"
                                                target-form="add-form"
                                                type="button">确 定
                                        </button>
                                        <button
                                                class="btn btn-default col-md-2"
                                                onclick="history.back(-1);return false;"
                                                type="button">返 回
                                        </button>
                                    </div>
                                </form>
                            </div>
            </div>
        </main>
        <!--End 页面主要内容-->
    </div>
</div>

<div th:insert="common/fragment::tail-script"></div>

<script type="text/javascript">
    $(function () {


        // 添加supplier按钮提交 - addsupplier.ajax
        $('#add-supplier-btn').on('click', function () {

            let id = $('#supplierid').val()
            let suppliername = $('#suppliername').val();
            let supplieraddress = $('#supplieraddress').val();
            let linkman = $('#linkman').val();
            let phone = $('#phone').val();
            let email = $('#email').val();
            let comment = $('#comment').val();
            let status =$('input[name=supplierstatus]:checked').val()


            if(suppliername===''){
                    confirmMsg('请填写供应商名称')
                    return
            }


            //生成data -- json

            let data = {
                id: id,
                name : suppliername,
                address:supplieraddress,
                linkman: linkman,
                phone: phone,
                email: email,
                status: status,
                comment: comment
            }
            //   let data = $('#icon-form').serialize()
            post_ajax('/supplier/editsupplier.ajax', data, '/supplier/supplierlist.do');

        });

        // 页面 禁用按钮 -- 提交后台 切换状态为禁用


    });
</script>
</body>
</html>